home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / util / time / backclock.lha / backclock / sources / style / nodes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  2.6 KB  |  128 lines

  1. #include <pragmas/rtracker_pragmas.h>
  2. #include <exec/libraries.h>
  3. #include <exec/memory.h>
  4. #include <clib/rtracker_protos.h>
  5.  
  6. #include "main.h"
  7. #include "nodes.h"
  8.  
  9. extern struct Library * RTrackerBase ;
  10.  
  11. extern SPoint * ipoint,*current ;
  12.  
  13. void AddPoint(struct Window * win, ULONG x, ULONG y) {
  14.   /* add this point to the list relative to arrow centre (100,150)
  15.    */
  16.   SPoint * np ;
  17.  
  18.  
  19.   np = NewAllocVec(sizeof(SPoint), MEMF_PUBLIC|MEMF_CLEAR) ;
  20.   /* transform window x to normal x
  21.    * idem with y
  22.    */
  23.   if (np) {
  24.     /* when something goes wrong (memory shortage) then do nothing
  25.      */
  26.     x = x - win->BorderLeft + (GRID / 2) ;
  27.     y = y - win->BorderTop +  (GRID / 2) ;
  28.     x = x / GRID ;
  29.     y = y / GRID ;
  30.     x = x * GRID ;
  31.     y = y * GRID ;
  32.     np->x = x - PX ;
  33.     np->y = y - PY ;
  34.  
  35.     /*insert the point after the current one
  36.      */
  37.     np->next = current->next ;
  38.     current->next = np ;
  39.     /* make this new point, the current point
  40.      */
  41.     current = np ;
  42.   }
  43.  
  44.  
  45. }
  46.  
  47. BOOL RemPoint(struct Window * win, ULONG x, ULONG y) {
  48.   /* Delete a point from the list
  49.    */
  50.   BOOL deleted = FALSE ;
  51.   SPoint * pp,  // previous point
  52.          * dp ; // point to delete
  53.  
  54.   x = x - win->BorderLeft + (GRID / 2) ;
  55.   y = y - win->BorderTop +  (GRID / 2) ;
  56.   x = x / GRID ;
  57.   y = y / GRID ;
  58.   x = x * GRID - PX ;
  59.   y = y * GRID - PY ;
  60.  
  61.   pp = ipoint ;
  62.   dp = ipoint->next ;
  63.   while(dp) {
  64.     /* find the point
  65.      */
  66.     if((dp->x == x) && (dp->y == y)) {
  67.       /* point found
  68.        */
  69.       current = pp ;    /* change the current point to the previous point */
  70.       DeletePoint(pp) ;                     /* nb: delete pp->next not pp */
  71.       deleted = TRUE ;
  72.     }else {
  73.       /* go to next
  74.        */
  75.       pp = dp ;
  76.       dp = pp->next ;
  77.     }
  78.   }
  79.  
  80.   return(deleted) ;
  81. }
  82.  
  83. void SetCurPoint(struct Window * win, ULONG x, ULONG y) {
  84.   /* set the selected point the current one
  85.    */
  86.   SPoint * dp ; // point to be active
  87.  
  88.   x = x - win->BorderLeft + (GRID / 2) ;
  89.   y = y - win->BorderTop +  (GRID / 2) ;
  90.   x = x / GRID ;
  91.   y = y / GRID ;
  92.   x = x * GRID - 104 ;
  93.   y = y * GRID - 144 ;
  94.  
  95.   dp = ipoint->next ;
  96.   while(dp) {
  97.     /* find the point
  98.      */
  99.     if((dp->x == x) && (dp->y == y)) {
  100.       /* point found
  101.        */
  102.       current = dp ;
  103.     }
  104.     dp = dp->next ;
  105.   }
  106. }
  107. void ClearPoints(void) {
  108.   /* clear all the points
  109.    */
  110.   SPoint * sp ;
  111.   sp = ipoint ;
  112.   while(sp->next) {
  113.     DeletePoint(ipoint) ;
  114.   }
  115.   current = ipoint ;
  116. }
  117.  
  118. void DeletePoint(SPoint * previous) {
  119.   /* delete a single point
  120.    */
  121.   SPoint * del ;
  122.  
  123.   del = previous->next ;
  124.   previous->next = del->next ;
  125.   NewFreeVec(del) ;
  126.  
  127. }
  128.